========================================================================= 
Log Path: ./log/logf1.log 
Program Path: /Users/yorke/Dropbox/dissertation/3_Empirics/2_Code/cabinets/replication/02_rep_fig1.R 
Working Directory: /Users/yorke/Dropbox/dissertation/3_Empirics/2_Code/cabinets/replication 
User Name: yorke 
R Version: 4.2.1 (2022-06-23) 
Machine: AS23C1Q05N arm64 
Operating System: Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 
Base Packages: stats graphics grDevices utils datasets methods base Other Packages: tidylog_1.0.2 logr_1.3.3 forcats_1.0.0 stringr_1.5.0 dplyr_1.1.0 purrr_1.0.1 readr_2.1.3 tidyr_1.3.0 tibble_3.1.8 ggplot2_3.4.0 tidyverse_1.3.2 vdemdata_3.0 
Log Start Time: 2023-02-13 09:36:46 
========================================================================= 

> #### Replication Code for:
> #### Ministries Matter, Figure 1
> #### Author: Erin York
> #### Created: 2/3/2023
> 
> rm(list = ls())
> 
> library(vdemdata)
> library(tidyverse)
> library(logr)
> 
> options("logr.autolog" = TRUE)
> 
> # Open the log
> lf <- log_open(file.path("logf1.log"))
> 
> # Send message to log
> log_code()
> 
> # generate cab makeup data ------------------------------------------------
> 
> ## NOTE: this section of code generates the dataset cab_independents.csv using WhoGov data
> ## WhoGov_within_V2.0
> ## To generate Figure 1, skip to the next section
> 
> # load in whogov individual-level dataset (see readme for access) and set wd to file location
> whogov<- read.csv("WhoGov_within_V2.0.csv")
> 
> # count number of ministerial posts per countryyear
> allmins<- whogov %>%
>   filter(classification %in% c("Minister (Junior)", "Minister (Full Rank)")) %>% 
>   group_by(country_isocode, year) %>%
>   summarise(n_mins= n()) 
> 
> # count number of independent ministerial posts per countryyear
> ind<- whogov %>% 
>   filter(classification %in% c("Minister (Junior)", "Minister (Full Rank)"), 
>          party == "independent") %>% 
>   group_by(country_isocode, year) %>% summarise(independent = n())
> 
> cabdat<- allmins %>% 
>   full_join(ind) %>%
>   mutate(independent = ifelse(is.na(independent), 0, independent)) %>%
>   # generate non-partisan metric
>   mutate(prop_ind = independent/n_mins)
> 
> # uncomment the below to write cab_independents dataset
> #write_csv(x = cabdat, file = "cab_independents.csv")
> 
> 
> 
> # generate Figure 1 -------------------------------------------------------
> 
> # load in cabinet makeup data
> cabdat<- read_csv("cab_independents.csv")
> # load vdem data from package
> vdem<- vdem
> 
> fig1dat<- vdem %>% 
>   # remove regime-years where parties are banned altogether
>   filter(v2psparban_ord != 1) %>%
>   select(country_text_id, year, v2x_regime) %>% 
>   rename(country_isocode = country_text_id) %>%
>   filter(year >= 1970, year <= 2017) %>%
>   # autocracy indicator based on regimes in the world metric
>   mutate(Autocracy = ifelse(v2x_regime < 2, "Yes", "No")) %>%
>   # merge vdem regimes metric with cabinet data
>   right_join(cabdat) %>%
>   filter(!is.na(v2x_regime)) %>%
>   # generate regime type-year averages
>   group_by(Autocracy, year) %>%
>   summarise(ind =  mean(prop_ind))
> 
> ## Figure 1 ##
> fig1<- fig1dat %>%
>   ggplot(aes(x = year, y = ind, color = Autocracy, shape = Autocracy)) + 
>   geom_smooth(se = F, linewidth = .6) +
>   geom_point() + 
>   theme_bw() +
>   ylab("Proportion of Non-Partisan Ministers") +
>   xlab("") +
>   theme(legend.position = "bottom",
>         legend.key.size = unit(1, 'cm'))+
>   #  scale_color_viridis_d(begin = .1, end = .6) +
>   scale_color_brewer(palette = "Set2") +
>   ylim(c(0, NA)) 
> 
> ggsave(fig1, filename = "Figure1.pdf",
>        width = 8, height = 5)
> ####
> 
> log_close()

filter: removed 58,359 rows (23%), 191,598 rows remaining

NOTE: Log Print Time:  2023-02-13 09:36:51 
NOTE: Elapsed Time: 4.90265512466431 secs 

group_by: 2 grouping variables (country_isocode, year)

NOTE: Log Print Time:  2023-02-13 09:36:51 
NOTE: Elapsed Time: 0.00843596458435059 secs 

summarise: now 8,791 rows and 3 columns, one group variable remaining (country_isocode)

NOTE: Log Print Time:  2023-02-13 09:36:51 
NOTE: Elapsed Time: 0.0442888736724854 secs 

filter: removed 212,497 rows (85%), 37,460 rows remaining

NOTE: Log Print Time:  2023-02-13 09:36:51 
NOTE: Elapsed Time: 0.0360980033874512 secs 

group_by: 2 grouping variables (country_isocode, year)

NOTE: Log Print Time:  2023-02-13 09:36:51 
NOTE: Elapsed Time: 0.00332808494567871 secs 

summarise: now 4,179 rows and 3 columns, one group variable remaining (country_isocode)

NOTE: Log Print Time:  2023-02-13 09:36:51 
NOTE: Elapsed Time: 0.0221121311187744 secs 

full_join: added one column (independent)

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 1.04707384109497 secs 

           > rows only in x   4,612

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.0606400966644287 secs 

           > rows only in y       0

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.00126004219055176 secs 

           > matched rows     4,179

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.000886917114257812 secs 

           >                 =======

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.000825881958007812 secs 

           > rows total       8,791

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.000849008560180664 secs 

mutate (grouped): converted 'independent' from integer to double (4612 fewer NA)

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.00416803359985352 secs 

mutate (grouped): new variable 'prop_ind' (double) with 386 unique values and 0% NA

NOTE: Log Print Time:  2023-02-13 09:36:52 
NOTE: Elapsed Time: 0.0073540210723877 secs 

filter: removed 3,664 rows (13%), 23,716 rows remaining

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 4.84936213493347 secs 

select: dropped 4,167 variables (country_name, country_id, historical_date, project, historical, …)

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.0082399845123291 secs 

rename: renamed one variable (country_isocode)

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00189590454101562 secs 

filter: removed 15,937 rows (67%), 7,779 rows remaining

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00718402862548828 secs 

mutate: new variable 'Autocracy' (character) with 3 unique values and <1% NA

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00316596031188965 secs 

right_join: added 3 columns (n_mins, independent, prop_ind)

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.129959106445312 secs 

            > rows only in x  (  661)

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.0496499538421631 secs 

            > rows only in y   1,673

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.000956058502197266 secs 

            > matched rows     7,118

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.000903844833374023 secs 

            >                 =======

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00101017951965332 secs 

            > rows total       8,791

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.000955820083618164 secs 

filter: removed 1,673 rows (19%), 7,118 rows remaining

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00309896469116211 secs 

group_by: 2 grouping variables (Autocracy, year)

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00290203094482422 secs 

summarise: now 96 rows and 3 columns, one group variable remaining (Autocracy)

NOTE: Log Print Time:  2023-02-13 09:36:57 
NOTE: Elapsed Time: 0.00475215911865234 secs 

========================================================================= 
Log End Time: 2023-02-13 09:36:58 
Log Elapsed Time: 0 00:00:12 
========================================================================= 
